<?php

use Welcomescreen\Agavi\Action;

class Backend_LoginAction extends Action\BackendBaseAction {
	/**
	 * @param AgaviWebRequestDataHolder $rd
	 * @return string
	 */
	public function executeRead(AgaviWebRequestDataHolder $rd) {
		if($this->getContext()->getUser()->isAuthenticated()) {
			return 'Success';
		}
		return 'Input';
	}
	
	/**
	 * @param AgaviWebRequestDataHolder $rd
	 * @return string
	 */
	public function executeWrite(AgaviWebRequestDataHolder $rd) {
		$username = $rd->getParameter('username');
		$password = $rd->getParameter('password');
		if($this->getContext()->getUser()->login($username, $password)) {
			return 'Success';
		}
		return 'Input';
	}
	
	
	/**
	 * @param AgaviRequestDataHolder $rd
	 * @return string
	 */
	public function handleError(AgaviRequestDataHolder $d) {
		return 'Input';
	}
	
	/**
	 * @return string
	 */
	public function getDefaultViewName() {
		return 'Input';
	}
}

?>